<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
     <!-- 兼容移动端和PC端 -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" th:href="@{/css/semantic-UI/semantic.min.css}">
    <link rel="stylesheet" th:href="@{/lib/editormd/css/editormd.min.css}">
    <link rel="stylesheet" th:href="@{/css/me.css}">
    <title>发布博客</title>
</head>
<body>
    <!-- 导航 -->
    <!-- inverted 反转   attached 没有圆角 -->
    <nav th:replace="admin/_fragment :: menu(1)" class="ui inverted attached segment m-padded-tb-mini m-shadow-small">
        <div class="ui container">
            <!-- stackable屏幕下的时候可堆叠的 适应手机端 -->
            <div class="ui inverted secondary stackable menu">
                <h2 class="ui teal header item">博客管理</h2>
                <!-- 标签加了mini之后   火狐正常显示 edge错位显示  所以加上small -->
                <a href="#" class="active item m-item m-mobile-hide"><i class="small home icon"></i>首页</a>
                <a href="#" class="item m-item m-mobile-hide"><i class="small idea icon"></i>分类</a>
                <a href="#" class="item m-item m-mobile-hide"><i class="small tags icon"></i>标签</a>
                
                <div class="right menu">
                    <div class="ui dropdown m-item m-mobile-hide item">
                        <div class="text">
                            <img src="https://picsum.photos/id/103/100/100" alt="" class="ui avatar image">
                            陈楷
                        </div>
                        <i class="dropdown icon"></i>
                        <div class="menu">
                            <a href="#" class="item">注销</a>
                        </div>
                    </div>
                </div>

            </div>
        </div>
        <a href="#" class="ui menu toggle black icon button m-top-right m-mobile-show">
            <i class="sidebar icon"></i>
        </a>
    </nav>

    <div class="ui attached pointing menu">
        <div class="ui container">
            <div class="right menu">
                <a href="#" th:href="@{/admin/blogs/input}"  class="item active teal">发布</a>
                <a href="#" th:href="@{/admin/blogs}" class="item">列表</a>
            </div>
        </div>
    </div>
    

    <!-- 中间容器 -->
    <div class="m-padded-tb-big m-container">
        <div class="ui container">

            <form id="blog-form" action="#" th:object="${blog}" th:action="@{/admin/blogs}" class="ui form" method="post">
                <!---隐藏域设置保存和提交-->
                <input type="hidden" name="published">
                <!-- 设置隐藏域提交id  用于编辑博客 -->
                <input type="hidden" name="id" th:value="*{id}">
                <!-- 设置隐藏域提交view 浏览次数  用于编辑博客 -->
                <input type="hidden" name="views" th:value="*{views}">
                <div class="required field">
                    <div class="ui left labeled input">
                        <div class="ui selection compact teal basic dropdown label">
                            <input type="hidden" value="原创" name="flag" th:value="*{flag}">
                            <i class="dropdown icon"></i>
                            <div class="text">原创</div>
                            <div class="menu">
                                <div class="item" data-value="原创">原创</div>
                                <div class="item" data-value="转载">转载</div>
                                <div class="item" data-value="翻译">翻译</div>
                            </div>
                        </div>
                        <input type="text" name="title" placeholder="标题" th:value="*{title}">
                    </div>
                </div>

                <!-- markdown编辑器 -->
                <div class="required field">
                    <div id="md-content" style="z-index: 1 !important;">
                        <textarea placeholder="博客内容" th:text="*{content}" name="content" id="content" style="display: none;"></textarea>
                    </div>
                </div>

                <!--分类和标签按钮-->
                <div class="two fields">
                    <div class="required field">
                        <div class="ui left labeled action input">
                            <div class="ui compact teal basci label">分类</div>
                            <div class="ui fluid selection dropdown">
                                <input type="hidden" name="type.id" th:value="*{type}!=null?*{type.id}">
                                <i class="dropdown icon"></i>
                                <div class="default text">分类</div>
                                <div class="menu">
                                    <div class="item" th:each="type : ${types}" th:text="${type.name}"
                                         th:data-value="${type.id}"></div>
                                    <!--<div class="item" data-value="1">错误日志</div>-->
                                    <!--<div class="item" data-value="2">开发者手册</div>-->
                                </div>
                            </div>
                        </div>
                    </div>
                    <!--标签-->
                    <div class="field">
                        <div class="ui left labeled action input">
                            <label class="ui compact teal basic label">标签</label>
                            <div class="ui tag fluid selection multiple search  dropdown">
                                <input type="hidden" name="tagIds" th:value="*{tagIds}">
                                <i class="dropdown icon"></i>
                                <div class="default text">标签</div>
                                <div class="menu">
                                    <div th:each="tag : ${tags}" class="item" data-value="1" th:data-value="${tag.id}"
                                         th:text="${tag.name}">java
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!--首页图片地址-->
                <div class="required field">
                    <div class="ui left labeled input">
                        <label for="firstPicture" class="ui teal basic label">首图</label>
                        <input type="text" name="firstPicture" th:value="*{firstPicture}" id="firstPicture" placeholder="首图引用地址">
                    </div>
                </div>

                <!--是否推荐转载等等-->
                <div class="inline fields">
                    <div class="field">
                        <div class="ui checkbox">
                            <input type="checkbox" id="recommend" name="recommend" th:checked="*{recommend}" checked class="hidden">
                            <label for="recommend">推荐</label>
                        </div>
                    </div>
                    <div class="field">
                        <div class="ui checkbox">
                            <input type="checkbox" id="shareStatement" name="shareStatement" th:checked="*{shareStatement}"  class="hidden">
                            <label for="shareStatement">转载声明</label>
                        </div>
                    </div>
                    <div class="field">
                        <div class="ui checkbox">
                            <input type="checkbox" id="appreciation" name="appreciation" th:checked="*{appreciation}" class="hidden">
                            <label for="appreciation">赞赏</label>
                        </div>
                    </div>
                    <div class="field">
                        <div class="ui checkbox">
                            <input type="checkbox" id="commenttabled" name="commenttabled" th:checked="*{commenttabled}" class="hidden">
                            <label for="commenttabled">评论</label>
                        </div>
                    </div>
                </div>

                <div class="required field">
                    <div class="field">
                        <textarea rows="4" cols="13" id="description" placeholder="博客简介" th:text="*{description}" name="description"></textarea>
                    </div>
                </div>

                <!-- 显示错误信息 -->
                <div class="ui error message"></div>

                <div class="ui right aligned container">
                    <!-- button默认是提交 submit -->
                    <button type="button" class="ui button" onclick="window.history.go(-1)">返回</button>
                    <button id="save-btn" class="ui secondary button">保存</button>
                    <button id="published-btn" class="ui teal button">发布</button>
                </div>

            </form>
            
        </div>
    </div>


    <!-- 底部footer -->
    <footer th:replace="admin/_fragment::footer" class="ui  inverted vertical segment m-footer-padding-tb-massive">
        <div class="ui center aligned container   ">
            <div class="ui inverted divided stackable grid">
                <!--二维码-->
                <div class="three wide column">
                    <div class="ui inverted link list">
                        <div class="item">
                            <img th:src="@{../image/WeChat.jpg}" class="ui rounded image"
                                 style="width: 110px" alt=""/>
                        </div>
                    </div>
                </div>
                <!--文字-->
                <div class="three wide column">
                    <h4 class="ui inverted header m-text-thin m-text-spaced m-opacity-mini">最新博客</h4>
                    <div class="ui inverted link list">
                        <a href="#" class="item">用户故事</a>
                        <a href="#" class="item">江西龙头的故事</a>
                        <a href="#" class="item">陈楷的风光一生</a>
                    </div>
                </div>
                <div class="three wide column">
                    <h4 class="ui inverted header m-text-thin m-text-spaced ">联系我</h4>
                    <div class="ui inverted link list">
                        <a href="#" class="item">Emall:1240863484@qq.com</a>
                        <a href="#" class="item">QQ:1240863484</a>
                    </div>
                </div>
                <div class="seven wide column">
                    <h4 class="ui inverted header m-text-thin m-text-spaced ">博客简介</h4>
                    <p class="m-text-thin m-text-spaced  m-opacity-mini">
                        这是我的个人博客、会分享关于编程、写作、思考相关的任何内容、希望可以给来到这儿的人有所帮助...
                    </p>
                </div>
            </div>
            <div class="ui inverted section divider">
            <br>
            <br>
            <p class="m-text-thin m-text-spaced m-opacity-tiny">
                Copyright © 2022 - 06 - 01 Lirenmi Designed by Lirenmi
            </p>
            </div>
        </div>
    </footer>

<script th:src="@{/js/Jquery.js}"></script>
<script th:src="@{/css/semantic-UI/semantic.min.js}"></script>
<script th:src="@{/lib/editormd/editormd.min.js}"></script>

<script>

    /*初始化Markdown编辑器*/
     var contentEditor;
    $(function () {
        contentEditor = editormd("md-content", {
            width: "100%",
            height: 648,
            syncScrolling: "single",
            //path: "../../static/lib/editormd/lib/",
            path: "/lib/editormd/lib/",
            tocm: true, // Using [TOCM]
            tex: true, // 开启科学公式TeX语言支持，默认关闭
            flowChart: true, // 开启流程图支持，默认关闭
            emoji: true,
            //图片上传
            imageUpload : true,
            imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
            //上传图片的url
            imageUploadURL : "/admin/file/upload",

        });
    });

    // Emoji graphics files url path  表情包
    editormd.emoji     = {
      path : "/lib/editormd/plugins/emoji-dialog/emoji/",
      ext   : ".png"
    };

    $('.menu.toggle').click(function(){
        //点击这个按钮去除css中的m-mobile-hide样式
        $('.m-item').toggleClass('m-mobile-hide');
    });

    //注销按钮
    $('.ui.dropdown').dropdown({
            on: 'hover'
    });

    //保存隐藏域转态就是false
    $("#save-btn").click(function (){
        $('[name="published"]').val(false);
        $("#blog-form").submit();
    });
    //发布就是true
    $("#published-btn").click(function (){
        $('[name="published"]').val(true);
        $("#blog-form").submit();
    });

    $('.ui.tag.dropdown').dropdown({
        allowAdditions: true
    })

    // 表单验证
    $(".ui.form").form({
        fields : {
            title : {
                identifier: 'title',
                rules: [{
                    type : 'empty',
                    prompt : '标题，请输入标题'
                }]
            },
            content : {
                identifier: 'content',
                rules: [{
                    type : 'empty',
                    prompt : '博客，请输入博客内容'
                }]
            },
            firstPicture : {
                identifier: 'firstPicture',
                rules: [{
                    type : 'empty',
                    prompt : '请输入首图地址'
                }]
            },
            typeID : {
                identifier: 'type.id',
                rules: [{
                    type : 'empty',
                    prompt : '请输入分类'
                }]
            },
            description : {
                identifier: 'description',
                rules: [{
                    type : 'empty',
                    prompt : '请输入博客简介'
                }]
            }
        }
    })
</script>
</body>
</html>